package com.yuhanginfo.modules.web.web;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuhanginfo.modules.web.util.WebUserUtils;
import com.yuhanginfo.modules.web.entity.ShoppingCart;
import com.yuhanginfo.modules.web.entity.WebClass;
import com.yuhanginfo.modules.web.entity.WebYongUser;
import com.yuhanginfo.modules.web.service.ShoppingCartService;
import com.yuhanginfo.modules.web.service.WebClassService;

/**
 * EPC接口
 *
 */
@Controller
@RequestMapping(value = "${frontPath}/epcInterface")
public class EpcController {
	
	@Autowired
	private WebClassService webClassService;
	@Autowired
	private ShoppingCartService shoppingCartService;
	
	@RequestMapping(value = "getUser")
	@ResponseBody
	public WebYongUser getUser() {
		WebYongUser yongUser = WebUserUtils.getYongUser();
		if(yongUser.getId()!=null){
			return yongUser;
		}else{
			return null;
		}
	}
	
	@RequestMapping(value = "getClass")
	@ResponseBody
	public List<WebClass> getAllClasses() {
		return webClassService.getAllClasses();
	}
	
	@RequestMapping(value = "getShoppingCartNum")
	@ResponseBody
	public Integer getShoppingCartNum() {
		WebYongUser yongUser = WebUserUtils.getYongUser();
		List<ShoppingCart> selectByUserId = shoppingCartService.selectByUserId(yongUser.getId());
		return selectByUserId==null?0:selectByUserId.size();
	}
	
	
}
